#ifndef _BSP_USART_H_
#define _BSP_USART_H_

#include <rtconfig.h>

/*
    debug uart is USART2 according to schematic, but GD32 datasheet and user manual prescribed
    this usart as USART1 with calculation from USART0, therefore, it is necessary to use USART1 related macros,
    DMA channels and interrupt. One confusing thing is that USART2_IRQHandler should be used,
    as a result of interrupt vector replaces USART0_IRQHandler with USART1_IRQHandler.
*/

#define DEBUG_UART                USART1
#define DEBUG_RCU                 RCU_USART1
#define DEBUG_PIN_GROUP           GPIOA
#define DEBUG_TX_PIN              GPIO_PIN_2
#define DEBUG_RX_PIN              GPIO_PIN_3

#define DEBUG_UART_DMA_TX         /* if defined, means enable uart DMA transfer */
#define DEBUBG_UART_IDLE_DMA_RX   /* if defined, means select uart DMA receive with uart rx idle interrupt   \
                                  if not defined, means select uart RBNE(receive buffer not empty) interrupt \
                                  */

#define DEBUG_UART_TX_BUFFER_SIZE 512
#define DEBUG_UART_RX_BUFFER_SIZE 128

#define DEBUG_USART_DMA           DMA0
#define DEBUG_UART_TX_DMA_CHANNEL DMA_CH6
#define DEBUG_UART_RX_DMA_CHANNEL DMA_CH5

#define DEBUG_UART_IRQ            USART1_IRQn
#define DEBUG_UART_HANDLER        USART1_IRQHandler

void debug_uart_dma_config(void);
int debug_uart_init(void);

#ifdef RT_USING_DEVICE
int init_debug_uart_device(void);
#endif

#define ESP12F_UART      UART3
#define ESP12F_UART_RCU  RCU_UART3
#define ESP12F_GPIO_RCU  RCU_GPIOC
#define ESP12F_PIN_GROUP GPIOC
#define ESP12F_TX_PIN    GPIO_PIN_10
#define ESP12F_RX_PIN    GPIO_PIN_11

int esp12f_uart_init(void);
#endif
